//
//  DianluView.m
//  engineeringDrawing
//
//  Created by BJB0004 on 17/4/1.
//  Copyright © 2017年 HangzhouBaixiongtechnologyco.,LTD. All rights reserved.
//

#import "DianluView.h"
#define BWITH 16.85
#define LHEIGHT 121.7
#define HEIGHT 60.1
@implementation DianluView
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    self.backgroundColor = [UIColor grayColor];
    
    return self;
}

-(void)drawRect:(CGRect)rect{
    
    [super drawRect:rect];
    
    [self drawMyView];
}

-(void)drawMyView{
    
    float w = self.frame.size.width;
    float h =self.frame.size.height;
    
    CGContextRef  ctx= UIGraphicsGetCurrentContext();
    
    //画空心的四边形
    CGContextStrokeRect(ctx, CGRectMake(0, 0, w, h));
    
    //    [[UIColor blueColor]set];
    //    //渲染
    
    CGContextFillPath(ctx);
    int hang = h/BWITH;
    
    for (int i =1; i<=hang+1; i++) {
        CGContextMoveToPoint(ctx, 0, BWITH*i);
        //设置终点
        CGContextAddLineToPoint(ctx, w,BWITH*i);
        CGContextStrokePath(ctx);
        if (i%2==0) {
            NSLog(@"%d",i);
            CGContextMoveToPoint(ctx, HEIGHT, BWITH*(i-1));
            //设置终点
            CGContextAddLineToPoint(ctx, HEIGHT,BWITH*i);
            CGContextStrokePath(ctx);
            
            int num = (w - HEIGHT)/LHEIGHT;
            //            int yu =((int)w - HEIGHT)%LHEIGHT;
            
            for (int j =1; j<=num+1; j++) {
                //设置起点
                CGContextMoveToPoint(ctx, HEIGHT+LHEIGHT*j, BWITH*(i-1));
                //设置终点
                CGContextAddLineToPoint(ctx, HEIGHT+LHEIGHT*j,BWITH*i);
                CGContextStrokePath(ctx);
            }
            
            
            
            
        }else{
            NSLog(@"%d",i);
            //            CGContextMoveToPoint(ctx, LHEIGHT, BWITH*(i-1));
            //            //设置终点
            //            CGContextAddLineToPoint(ctx, LHEIGHT,BWITH*i);
            //            CGContextStrokePath(ctx);
            int num = w/LHEIGHT;
            //           int yu =(int)w %LHEIGHT;
            
            for (int j =1; j<=num+1; j++) {
                //设置起点
                CGContextMoveToPoint(ctx, LHEIGHT*j, BWITH*(i-1));
                //设置终点
                CGContextAddLineToPoint(ctx, LHEIGHT*j,BWITH*i);
                CGContextStrokePath(ctx);
            }
            
            
            
        }
        
    }
    
    
    
    
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
